package com.speech.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;

import com.speech.R;
import com.speech.constant.PrefsConstant;
import com.speech.db.SharedPreferenceHelper;

public class EntranceActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_entrance);

        final Handler handler = new Handler(){
            @Override
            public void handleMessage(Message msg) {

                if (msg.what == 1) {
                    //已登录
                    startActivity(new Intent(EntranceActivity.this, HomeActivity.class));
                    finish();
                } else {
                    //未登录
                    startActivity(new Intent(EntranceActivity.this, LoginActivity.class));
                    finish();
                }

            }
        };


        new Thread(new Runnable(){
            @Override
            public void run() {
                SharedPreferenceHelper spf_helper = new SharedPreferenceHelper(EntranceActivity.this, PrefsConstant.FILE_USER_INFO);
                Integer iLoginState = (Integer) spf_helper.getData(PrefsConstant.KEY_USER_INFO_INT_LOGIN_STATE, SharedPreferenceHelper.INT_TYPE_DEFAULT);
                try {
                    Thread.sleep(1500L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                handler.sendEmptyMessage(iLoginState);

            }
        }).start();


    }
}
